﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;

namespace BlogManager.Core.BaseArchitecture
{
    public abstract class AppBasePage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            
            //Called evrytime.
            PageLoad();

            if (IsPostBack)
                PagePostBackLoad();
            else
            {
                PageFirstTimeLoad();
                PageDataLoad();
            }

        }

        public virtual void PageLoad()
        {

        }

        public virtual void PageFirstTimeLoad()
        {

        }

        public virtual void PageDataLoad()
        {

        }

        public virtual void PagePostBackLoad()
        {

        }

        public long? UserId {
            get 
            { 
                var princpal = Thread.CurrentPrincipal;
                if (princpal != null)
                    return Convert.ToInt64(princpal.Identity);

                return null;
            }
        }
    }
}